
import java.util.List;
import Dict.*;
import org.omg.CORBA.ORB;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author dtuanh
 */
public class DictionnaryTool {

    //determiner le type de category
    public static CategoryValue getCategoryType(String line) {
        int i = line.indexOf(",");
        int j = line.indexOf(",", i + 1);
        String tmp = line.substring(i + 1, j).trim();
        if (tmp.equals("NOM")) {
            return CategoryValue.NOM;

        } else if (tmp.equals("ADJ")) {
            return CategoryValue.ADJ;

        }
        return CategoryValue.VER;
    }

    //lire le terme
    public static String getTerm(String line) {
        int i = line.indexOf("«");
        int j = line.indexOf("»", i + 1);
        return line.substring(i + 1, j-1).trim();
    }

    //lire liste de property
    public static PropertyType getPropertyType(String line, CategoryValue type) {
        PropertyType ret=new PropertyType();
        int i = line.indexOf("<");
        int j = line.indexOf(">", i + 1);
        int n = -1;
        String property_ls = line.substring(i + 1, j).trim();
        if(type.value()==CategoryValue.NOM.value())
        {
            PropNom pro=null;
             n = property_ls.indexOf(",");
                String genre = property_ls.substring(0, n).trim();
                i = property_ls.indexOf("«", n);
                j = property_ls.indexOf("»", i + 1);
                String pluriel = property_ls.substring(i+1, j-1);


                if (genre.equals("MASC")) {
                  pro= new PropNom(PropGenreValue.MASC, pluriel);
                }
                if (genre.equals("FEM")) {
                   pro= new PropNom(PropGenreValue.FEM, pluriel);
                }
                ret.pNom(pro);
                return ret;
        }
        if(type.value()==CategoryValue.ADJ.value())
        {
            PropAdj pro=null;
             i = property_ls.indexOf("«");
                j = property_ls.indexOf("»", i + 1);
                String feminin = property_ls.substring(i+1, j-1);
                n = property_ls.indexOf(",");
                i = property_ls.indexOf("«", n);
                j = property_ls.indexOf("»", i + 1);
                String pluriel = property_ls.substring(i+1, j-1);
                pro=new PropAdj(feminin, pluriel);
                ret.pAdj(pro);
                return ret;
        }
        if(type.value()==CategoryValue.VER.value())
        {
            PropVer pro=null;
            n = property_ls.indexOf(",");
                String group = property_ls.substring(0, n).trim();
                String transitive = property_ls.substring(n + 1).trim();
                //System.out.println("TRANS:"+transitive);
                int n_group=Integer.parseInt(group);
                if (transitive.equals("TRANS")) {
                    if(n_group==1)
                    pro=new PropVer(PropGroupeValue.G1, PropTransValue.TRANS);
                    if(n_group==2)
                    pro=new PropVer(PropGroupeValue.G2, PropTransValue.TRANS);
                    if(n_group==3)
                    pro=new PropVer(PropGroupeValue.G3, PropTransValue.TRANS);
                } else if (transitive.equals("INTR")) {
                   if(n_group==1)
                    pro=new PropVer(PropGroupeValue.G1, PropTransValue.INTR);
                    if(n_group==2)
                    pro=new PropVer(PropGroupeValue.G2, PropTransValue.INTR);
                    if(n_group==3)
                    pro=new PropVer(PropGroupeValue.G3, PropTransValue.INTR);
                }
                ret.pVer(pro);
                return ret;
        }
       
        return ret;

    }

    //Lire un WORD objet
    public static WordImpl readWord(String line) {
        WordImpl word = new WordImpl();
        CategoryValue cate =getCategoryType(line);
        word.setCategory(cate);
        word.setTerm(getTerm(line));
        word.setProperty(getPropertyType(line, cate));
        return word;
    }
//lire la definition de mot
    public static String readDefinition(String line) {
        int i = line.indexOf("«");
        int j = line.indexOf("»", i + 1);
        return line.substring(i + 1, j-1).trim();
    }
}
